package com.ckd.flyingtrip.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;

import com.ckd.flyingtrip.R;

public class OptionUserFKAdapter extends RecyclerView.Adapter<OptionUserFKAdapter.MyHolder> {

    private Context context;
    private String[] strings;
    private boolean[] booleans;
    public OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }

    public OptionUserFKAdapter(Context context, String[] strings, boolean[] booleans) {
        this.context = context;
        this.strings = strings;
        this.booleans = booleans;
    }

    @NonNull
    @Override
    public MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MyHolder(LayoutInflater.from(context).inflate(R.layout.item_userfk_recyclerview, null));
    }

    @Override
    public void onBindViewHolder(@NonNull MyHolder holder, int position) {
        holder.textView.setText(strings[position]);
        if (!booleans[position]) {
            holder.textView.setBackground(ContextCompat.getDrawable(context, R.drawable.shape_5_edf0f0_by));
            holder.textView.setTextColor(ContextCompat.getColor(context, R.color.color_333));
        } else {
            holder.textView.setBackground(ContextCompat.getDrawable(context, R.drawable.shape_5_f3800f_by));
            holder.textView.setTextColor(ContextCompat.getColor(context, R.color.white));
        }

        holder.textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onItemClickListener.onItemClick(v, position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return strings.length;
    }

    public class MyHolder extends RecyclerView.ViewHolder {
        TextView textView;

        public MyHolder(@NonNull View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.item_userfk_recyclerview_textView);
        }
    }
}
